package com.engine4cloud.tdf.supervision.controller.inner;

import cn.hutool.core.collection.CollUtil;
import com.engine4cloud.tdf.common.core.util.R;
import com.engine4cloud.tdf.common.data.web.response.PageInfo;
import com.engine4cloud.tdf.common.log.annotation.SysLog;
import com.engine4cloud.tdf.common.security.annotation.Inner;
import com.engine4cloud.tdf.supervision.dto.create.RcglInvestigateCreateDTO;
import com.engine4cloud.tdf.supervision.dto.query.RcglInvestigateQueryDTO;
import com.engine4cloud.tdf.supervision.dto.result.RcglInvestigateResultDTO;
import com.engine4cloud.tdf.supervision.dto.update.RcglInvestigateUpdateDTO;
import com.engine4cloud.tdf.supervision.service.RcglInvestigateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

/**
 * 实地查访-inner
 *
 * @author wenjie
 * @date 2024-05-30 12:02:59
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/inner/investigate")
@Tag(description = "Investigate", name = "日常管理-实地查访-inner")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class RcglInvestigateInnerController {

    private final RcglInvestigateService investigateService;

    /**
     * 分页查询
     *
     * @param dto  实地查访
     * @return R<PageInfo < RcglInvestigateResultDTO>>
     */
    @Inner
    @Operation(summary = "分页查询", description = "分页查询")
    @PostMapping("/page")
    public R<PageInfo<RcglInvestigateResultDTO>> getPageList(@Valid @RequestBody RcglInvestigateQueryDTO dto) {
        return R.ok(investigateService.getPageList(dto));
    }


    /**
     * 通过id查询实地查访
     *
     * @param id id
     * @return R
     */
    @Inner
    @Operation(summary = "通过id查询", description = "通过id查询")
    @GetMapping("/{id}")
    public R<RcglInvestigateResultDTO> getById(@PathVariable("id") Long id) {
        return R.ok(investigateService.getById(id));
    }

    /**
     * 新增实地查访
     *
     * @param dto 实地查访
     * @return R
     */
    @Inner
    @Operation(summary = "新增实地查访", description = "新增实地查访")
    @SysLog("新增实地查访")
    @PostMapping
    public R<Boolean> create(@Valid @RequestBody RcglInvestigateCreateDTO dto) {
        return R.ok(investigateService.create(dto));
    }

    /**
     * 修改实地查访
     *
     * @param dto 实地查访
     * @return R
     */
    @Inner
    @Operation(summary = "修改实地查访", description = "修改实地查访")
    @SysLog("修改实地查访")
    @PutMapping
    public R<Boolean> update(@Valid @RequestBody RcglInvestigateUpdateDTO dto) {
        return R.ok(investigateService.update(dto));
    }

    /**
     * 通过id删除实地查访
     *
     * @param ids id列表
     * @return R
     */
    @Inner
    @Operation(summary = "通过id删除实地查访", description = "通过id删除实地查访")
    @SysLog("通过id删除实地查访")
    @DeleteMapping
    public R<Boolean> removeById(@RequestBody Long[] ids) {
        return R.ok(investigateService.removeBatchByIds(CollUtil.toList(ids)));
    }
}